home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / LOCALMFC.PAK / LOCALPPG.CPP < prev    next >
C/C++ Source or Header  |  1997-05-06  |  5KB  |  190 lines

  1. // localppg.cpp : Implementation of the CLocalizePropPage property page class.
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1992-1995 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Microsoft Foundation Classes Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Microsoft Foundation Classes product.
  12.  
  13. #include "stdafx.h"
  14. #include "localize.h"
  15. #include "localppg.h"
  16.  
  17. #ifdef _WIN32
  18.   #include <winnt.h>
  19. #else
  20.   #include <olenls.h>
  21. #endif
  22.  
  23. #ifdef _DEBUG
  24. #undef THIS_FILE
  25. static char BASED_CODE THIS_FILE[] = __FILE__;
  26. #endif
  27.  
  28.  
  29. IMPLEMENT_DYNCREATE(CLocalizePropPage, COlePropertyPage)
  30.  
  31.  
  32. /////////////////////////////////////////////////////////////////////////////
  33. // Message map
  34.  
  35. BEGIN_MESSAGE_MAP(CLocalizePropPage, COlePropertyPage)
  36.     //{{AFX_MSG_MAP(CLocalizePropPage)
  37.     // NOTE - ClassWizard will add and remove message map entries
  38.     //    DO NOT EDIT what you see in these blocks of generated code !
  39.     //}}AFX_MSG_MAP
  40. END_MESSAGE_MAP()
  41.  
  42.  
  43. /////////////////////////////////////////////////////////////////////////////
  44. // Initialize class factory and guid
  45.  
  46. IMPLEMENT_OLECREATE_EX(CLocalizePropPage, "LOCALIZE.LocalizePropPage.1",
  47.     0x35e3e54, 0x6745, 0x101b, 0xb5, 0x7b, 0x0, 0x60, 0x8c, 0xc9, 0x6a, 0xfa)
  48.  
  49.  
  50. /////////////////////////////////////////////////////////////////////////////
  51. // CLocalizePropPage::CLocalizePropPageFactory::UpdateRegistry -
  52. // Adds or removes system registry entries for CLocalizePropPage
  53.  
  54. BOOL CLocalizePropPage::CLocalizePropPageFactory::UpdateRegistry(BOOL bRegister)
  55. {
  56.     if (bRegister)
  57.         return AfxOleRegisterPropertyPageClass(AfxGetInstanceHandle(),
  58.             m_clsid, IDS_LOCALIZE_PPG);
  59.     else
  60.         return AfxOleUnregisterClass(m_clsid, NULL);
  61. }
  62.  
  63.  
  64. /////////////////////////////////////////////////////////////////////////////
  65. // CLocalizePropPage::CLocalizePropPage - Constructor
  66.  
  67. CLocalizePropPage::CLocalizePropPage() :
  68.     COlePropertyPage(IDD, IDS_LOCALIZE_PPG_CAPTION)
  69. {
  70.     //{{AFX_DATA_INIT(CLocalizePropPage)
  71.     m_Invert = FALSE;
  72.     //}}AFX_DATA_INIT
  73.  
  74.     hResHandle = NULL;
  75. }
  76.  
  77.  
  78. /////////////////////////////////////////////////////////////////////////////
  79. // CLocalizePropPage::DoDataExchange - Moves data between page and properties
  80.  
  81. void CLocalizePropPage::DoDataExchange(CDataExchange* pDX)
  82. {
  83.     //{{AFX_DATA_MAP(CLocalizePropPage)
  84.     DDP_Check(pDX, IDC_CHECK1, m_Invert, _T("Invert") );
  85.     DDX_Check(pDX, IDC_CHECK1, m_Invert);
  86.     //}}AFX_DATA_MAP
  87.     DDP_PostProcessing(pDX);
  88. }
  89.  
  90.  
  91. /////////////////////////////////////////////////////////////////////////////
  92. // Set the resource handle to the module which contains locale-specific
  93. // resources
  94.  
  95. void CLocalizePropPage::OnSetPageSite()
  96. {
  97.     BOOL bError = FALSE;
  98.     LCID lcid = 0;
  99.  
  100.     LPPROPERTYPAGESITE pSite = GetPageSite();
  101.     if (pSite != NULL)
  102.         pSite->GetLocaleID(&lcid);
  103.  
  104.     // Get the handle of the resource module
  105.     hResHandle = GetResourceHandle(lcid);
  106.  
  107.     #ifdef _WIN32
  108.         if (!hResHandle)
  109.         bError = TRUE;
  110.     #else
  111.         if (hResHandle <= HINSTANCE_ERROR)
  112.         bError = TRUE;
  113.     #endif
  114.  
  115.     if (!bError)
  116.     {
  117.         // Use resources from resource module
  118.         HINSTANCE hResPrev = AfxGetResourceHandle();
  119.         AfxSetResourceHandle(hResHandle);
  120.         COlePropertyPage::OnSetPageSite();
  121.         AfxSetResourceHandle(hResPrev);
  122.     }
  123.     else
  124.         // Use resources from control module
  125.         COlePropertyPage::OnSetPageSite();
  126. }
  127.  
  128.  
  129. /////////////////////////////////////////////////////////////////////////////
  130. // CLocalizePropPage::OnFinalRelease - Frees locale-specific resource
  131. // module, if any.
  132.  
  133. void CLocalizePropPage::OnFinalRelease()
  134. {
  135.     if (hResHandle != NULL)
  136.     {
  137.         FreeLibrary(hResHandle);
  138.         hResHandle = NULL;
  139.     }
  140.  
  141.     COlePropertyPage::OnFinalRelease();
  142. }
  143.  
  144.  
  145. /////////////////////////////////////////////////////////////////////////////
  146. // CLocalizePropPage::GetResourceHandle - Load module which contains
  147. // locale-specific resources
  148.  
  149. HINSTANCE CLocalizePropPage::GetResourceHandle(LCID lcid)
  150. {
  151.     LPCTSTR lpszResModule = NULL;
  152.     HINSTANCE hResHandle = NULL;
  153.  
  154.     // Use lcid to determine module that contains resources
  155.     LANGID langID = LANGIDFROMLCID(lcid);
  156.     unsigned short priLangID = (unsigned short) PRIMARYLANGID(langID);
  157.     switch (priLangID)
  158.     {
  159.         case LANG_ENGLISH:
  160.             break;
  161.         case LANG_FRENCH:
  162.             #ifdef _WIN32
  163.                 lpszResModule = (LPCTSTR)_T("lresfr32.dll");
  164.             #else
  165.                 lpszResModule = (LPCTSTR)_T("locresfr.dll");
  166.             #endif
  167.             break;
  168.         case LANG_GERMAN:
  169.             #ifdef _WIN32
  170.                 lpszResModule = (LPCTSTR)_T("lresde32.dll");
  171.             #else
  172.                 lpszResModule = (LPCTSTR)_T("locresde.dll");
  173.             #endif
  174.             break;
  175.         case 0:
  176.         default:
  177.              break;
  178.     }
  179.  
  180.     // Load resource module
  181.     if (lpszResModule != NULL)
  182.         hResHandle = LoadLibrary(lpszResModule);
  183.  
  184.     return hResHandle;
  185. }
  186.  
  187.  
  188. /////////////////////////////////////////////////////////////////////////////
  189. // CLocalizePropPage message handlers
  190.